package com.jcl.recruit.depart.dao;

import com.jcl.core.db.DatabaseContext;
import com.jcl.recruit.org.mapper.DepartmentMapper;
import com.jcl.recruit.org.model.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Component
public class DepartmentDao implements DepartmentMapper {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(Integer superId,
                                                                                  Integer subcompanyId,
                                                                                  String keyword) {
        DatabaseContext.setCurrentContext();
        return departmentMapper.selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(superId, subcompanyId, keyword);
    }

    @Override
    public Department findRootByCorpCode(String corpCode, Integer superId) {
        DatabaseContext.setContext(corpCode);
        return departmentMapper.findRootByCorpCode(corpCode, superId);
    }

    @Override
    public Department selectPrimarykeyById(Integer id) {
        DatabaseContext.setCurrentContext();
        return departmentMapper.selectPrimarykeyById(id);
    }

    @Override
    public List<Department> selectAllDepartmentsBySubaccountId(Integer superId,
                                                               Integer subcompanyId) {
        DatabaseContext.setCurrentContext();
        return departmentMapper.selectAllDepartmentsBySubaccountId(superId, subcompanyId);
    }

    @Override
    public int add(Department department) {
        DatabaseContext.setContext(department.getCorpCode());
        return departmentMapper.add(department);
    }
}
